import nameMap from './nameMap';
let mapName = 'world';

var convertData = (geoCoordMap = {}, data = [], type = '货轮') => {
    let res = [];
    data.map((item,i) => {
        //let dataItem = data[i];
        let fromCoord = geoCoordMap[item[0].name];
        let toCoord = geoCoordMap[item[1].name];
        let value = type == "货轮" ? item[0].value2 : item[0].value1;
        if (fromCoord && toCoord && value) {
            res.push({
                fromName: item[0].name,
                toName: type == "货轮" ? '南沙货运港' : "白云机场", //dataItem[1].name,
                coords: [fromCoord, toCoord],
                value1: item[0].value1,
                value2: item[0].value2,
                type: type
                //curveness:i*0.1+0.1
            });
        }
    });
    return res;
};

let planePath = 'path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z';
let shipPath = 'image://'

function getOpt({
    data = [],
    toolTipData = [],
    visualMapText = '累计确诊人数',
    geoCoordMap,
    BJData
} = {}) {
    console.log(data)
    let series = [];
    [
        ['广州', BJData]
    ].forEach(function (item, i) {
        series.push({
            name: "确诊病例",
            type: "map",
            map: mapName,
            showLegendSymbol: false, // 存在legend时显示
            geoIndex: 0,
            data: data
        }, {
            name: '飞机',
            type: 'lines',
            zlevel: 2,
            symbol: ['none', 'arrow'],
            symbolSize: 10,
            effect: {
                show: true,
                period: 16,
                trailLength: 0,
                symbol: planePath,
                symbolSize: 30
            },
            lineStyle: {
                normal: {
                    color: '#46bee9',
                    width: 3,
                    opacity: 1,
                    curveness: 0.6
                }
            },
            data: convertData(geoCoordMap, item[1], '飞机')
        }, {
            name: '货轮',
            type: 'lines',
            zlevel: 2,
            symbolSize: 10,
            symbol: ['none', 'arrow'],
            label: {
                show: false,
                color: '#fff'
            },
            effect: {
                show: true,
                period: 16,
                trailLength: 0,
                symbol: shipPath,
                symbolSize: 26,
            },
            lineStyle: {
                color: '#a6c84c',
                width: 3,
                opacity: 1,
                curveness: 0.2
            },
            data: convertData(geoCoordMap, item[1], '货轮')
        });
    });
    let option = {
        title: {
            text: '世界新冠肺炎分布',
            left: 'center',
            top: 'top',
            show: false
        },
        tooltip: {
            //triggerOn: "click",
            trigger: 'item',
            formatter: function (e, t, n) {
                let isExistData = toolTipData.get(e.name);
                let splitData = isExistData ? isExistData.split('-') : ['无数据', '无数据', '无数据', '无数据'];
                let toolTiphtml = '';
                if (e.seriesType == "lines") {
                    toolTiphtml += `${e.seriesName}：<br />${e.data.fromName}>${e.data.toName}<br />数量：${e.data.type=='货轮'?e.data.value2:e.data.value1}`
                } else {
                    toolTiphtml += `${e.name}：<br />累计确诊人数：${splitData[0]||0}<br />现有确诊人数：${splitData[3]||0}<br />治愈人数：${splitData[1]||0}<br />死亡人数：${splitData[2]||0}`
                }
                return toolTiphtml;
            }
        },
        toolbox: {
            show: false,
            orient: 'vertical',
            left: 'right',
            top: 'center',
            feature: {
                dataView: {
                    readOnly: false
                },
                restore: {},
                saveAsImage: {}
            }
        },
        visualMap: {
            min: 0,
            max: 1000000,
            left: 0,
            bottom: 70,
            showLabel: true,
            text: [visualMapText],
            itemWidth: 14,
            itemHeight: 14,
            textStyle: {
                color: '#000',
                fontSize: 16,
            },
            pieces: [{
                gt: 5000,
                //value: 6,
                label: "5000人以上",
                color: "#950C0C"
            }, {
                gte: 1000,
                lte: 4999,
                //value: 5,
                label: "1000-4999人",
                color: "#BC0F0F"
            }, {
                gte: 500,
                lte: 999,
                //value: 4,
                label: "500>999人",
                color: "#DA3A3A"
            }, {
                gte: 100,
                lte: 499,
                // value: 3,
                label: "100-499人",
                color: "#E56B04"
            }, {
                gte: 10,
                lte: 99,
                // value: 2,
                label: "10-99人",
                color: "#DE8539"
            }, {
                gte: 1,
                lte: 9,
                // value: 1,
                label: "1-9人",
                color: "#E19E65"
            }, {
                gte: 0,
                lte: 9,
                // value: 0,
                label: "0人",
                color: "#05910E"
            }],
            show: true
        },
        geo: {
            name: '世界新冠肺炎分布',
            map: mapName,
            type: 'map',
            roam: false,
            top: 140,
            zoom: 1.1,
            nameMap: nameMap,
            itemStyle: {
                normal: {
                    areaColor: 'rgba(0,0,0,.05)',
                    shadowBlur: 1
                }
            },
            label: {
                normal: {
                    show: false,
                    fontSize: "16",
                    color: "#fff"
                }
            },
            emphasis: {
                label: {
                    show: true,
                    color: '#fff',
                    fontSize: 18
                },
                itemStyle: {
                    //borderColor: '#fff',
                    borderWidth: 1
                }
            },
        },
        series: series
    };
    return option;
}

export default getOpt;